package com.estronger.shopmanage.adapter.tasking;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.bean.DeliverTrip;
import com.estronger.shopmanage.utils.ConvertUtils;
import com.estronger.shopmanage.view.CustomListView;

import java.util.ArrayList;


public class DelivertripAdpter extends BaseAdapter {

    private ArrayList<DeliverTrip.Datas> mList;
    Context mContext;

    public DelivertripAdpter(Context context, ArrayList<DeliverTrip.Datas> lt) {
        mContext = context;
        mList = lt;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if (mList != null)
            return mList.size();
        else
            return 0;
    }

    @Override
    public DeliverTrip.Datas getItem(int position) {
        // TODO Auto-generated method stub
        if (mList == null || mList.size() <= 0)
            return null;
        else
            return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final ListItemView ltv;

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.adpter_delivertrip, null);
            ltv = new ListItemView();
            ltv.sname = (TextView) convertView
                    .findViewById(R.id.sname);
            ltv.rwl_tt = (TextView) convertView.findViewById(R.id.rwl_tt);
            ltv.deliverdetail = (CustomListView) convertView.findViewById(R.id.deliverdetail);

            convertView.setTag(ltv);
        } else {
            ltv = (ListItemView) convertView.getTag();
        }

        try {
            ltv.sname.setText(ConvertUtils.formatNull(mList.get(position).dlvmanname));
            ltv.rwl_tt.setText(ConvertUtils.formatNull(mList.get(position).dlvcount));

            DelivertripDetailAdpter dda = new DelivertripDetailAdpter(mContext, mList.get(position).dlvdata);
            ltv.deliverdetail.setAdapter(dda);
//            //自动算高度
//            LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) ltv.deliverdetail.getLayoutParams();
//            linearParams.height = DensityUtils.dp2px(mContext, 75) * mList.get(position).dlvdata.size();
//            ltv.deliverdetail.setLayoutParams(linearParams);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    class ListItemView {
        TextView sname;
        TextView rwl_tt;
        CustomListView deliverdetail;
    }
}
